<?php
	include_once("../includes/header.php");
	include_once("../includes/common.php");
	include_once("../includes/connect.php");
	include_once("../includes/functions.php");
	
	if (isset($_GET["i"]))
	{
		$question_info_sql = "SELECT * from question WHERE id = '".$_GET["i"]."'";
		$question_info = $conn1->Execute($question_info_sql);

		if ($question_info->RecordCount() > 0)
		{

			if ($_SERVER['REQUEST_METHOD'] == "POST")
			{
				if ($_POST["submit"] != "No")
				{
					$mode = "edit";
					include_once("../includes/validatequestion.php");
				}
			}
			
			if (sizeof($errors) > 0 || ($_SERVER['REQUEST_METHOD'] == "POST" && $_POST["submit"] == "No") || $_SERVER['REQUEST_METHOD'] != "POST")
			{
	?>
	<h3>Update Question - <i><?php echo $question_info->fields["qstatement"];?></i></h3>
	<form action="<?php echo $_SERVER['../question/PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>" method="post" >
		<ol>
		  <li>
			<label for="name">Descriptive Statement *</label>
			<input name="qstatement" class="text" value="<?php echo (isset($_POST["qstatement"])) ? $_POST["qstatement"] : $question_info->fields["qstatement"]; ?>" />
		  </li>
		  <li>
			<label for="name">Presentation</label>
			<select name="is_lab" >
				<option value="0" <?php echo (isset($_POST["is_lab"]) ? $_POST["is_lab"] : $question_info->fields["is_lab"] ) == 0 ? "selected" : ""; ?>>Lecture</option>
				<option value="1" <?php echo (isset($_POST["is_lab"]) ? $_POST["is_lab"] : $question_info->fields["is_lab"] ) == 1 ? "selected" : ""; ?>>Laboratory</option>
			</select>
		  </li>		  
		  <li>
			<label for="name">Group</label>
			<select name="qgroupid" >
			<?php
				$data = $conn1->Execute("SELECT id as id, name as name FROM qgroup WHERE deleted = '0'");
				$qgroupid = ($question_info->fields["qcategoryid"] == "2") ? 1 : $question_info->fields["qgroupid"];
				dropDownOptions("id","name",$data,(isset($_POST["qgroupid"]) ? $_POST["qgroupid"] : $qgroupid ));
			?>

			</select>
			
		  </li>		  
		  <li>
			<label for="name"></label>
			<p style="font-style: italic; font-size: 10px; color:#333333"><b>Note</b>: IGNORE Group for Qualitative Questions</p>
		  </li>		  
		  <li>
			<label for="name">Category</label>
			<select name="qcategoryid" >
			<?php
				$data = $conn1->Execute("SELECT id as id, name as name FROM qcategory WHERE deleted = '0'");
				dropDownOptions("id","name",$data,(isset($_POST["qcategoryid"]) ? $_POST["qcategoryid"] : $question_info->fields["qcategoryid"] ));
			?>
			</select>
		  </li>		  
		  <li>
			<label>&nbsp;</label>
			<input type="submit" name="submit" value="Submit" onClick="" />
		  </li>
		</ol>
	</form>	 

<?php 
			}
		}
		else
			header("Location: viewqgroups.php"); // redirect if bad id
	}
	else
		header("Location: viewqgroups.php"); // redirect if no id supplied
	include_once("../includes/sidebar.php");
	include_once("../includes/footer.php");
?>
